package org.company.management.controller;

import java.util.Calendar;

import org.eclipse.nebula.widgets.ganttchart.GanttChart;
import org.eclipse.nebula.widgets.ganttchart.GanttEvent;

/**
 * @author Paner
 *
 */
public class GanttController
{
	
	private static Calendar _lastDate;
	
	/*john
	 *  
	 */
	public static Calendar getLastDate()
	{
		Calendar lastDate= null;
		if(_lastDate == null)
		{
			lastDate = Calendar.getInstance();
		}
		else
		{
			lastDate = (Calendar)_lastDate.clone();
		}
		return lastDate;
	}
	/*john
	 * 
	 */
	public static void updateLastDate(GanttChart ganttChart)
	{
		_lastDate = Calendar.getInstance();
		for(Object event : ganttChart.getGanttComposite().getEvents())
		{
			GanttEvent ganttEvent = (GanttEvent)event;
			Calendar currentEventDate = ganttEvent.getRevisedEnd();
			if(currentEventDate.after(_lastDate))
			{
				_lastDate = currentEventDate;
			}
		}
	}
	/*john
	 * 
	 */
	public static void updateLastDate(Calendar newDate)
	{
		if(newDate == null)
		{
			//
		}

		if(_lastDate == null || newDate.after( _lastDate))
		{
			_lastDate = newDate;
		}
	}
	
}
